package mysql

import (
	"database/sql"
	"errors"
	"go.uber.org/zap"
	"hr/models"
)

func GetCommunityList() (data []*models.Community, err error) {
	sqlStr := "select * from community"
	if err = db.Select(&data, sqlStr); err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			zap.L().Warn("there is no community", zap.String("sql", sqlStr))
			err = nil
		}
	}
	return

}
func GetCommunityDetail(id int64) (*models.Community, error) {
	community := new(models.Community)
	sqlStr := "select * from community where id=?"
	if err := db.Get(community, sqlStr, id); err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			err = ErrInvalidId
			zap.L().Warn("there is no community", zap.String("sql", sqlStr))
		}
		return nil, err
	}
	return community, nil
}
